package tr.gov.tubitak.bilgem.esya.crlviewer;

import javax.swing.table.DefaultTableModel;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: ramazan.girgin
 * Date: 4/18/12
 * Time: 11:10 AM
 * To change this template use File | Settings | File Templates.
 */
public class ERevokedCertsModel extends DefaultTableModel{

    static final int MODEL_COLUMN_COUNT=3;
    static final int MODEL_COLUMN_NUM_FIELD_SERIAL_NUMBER=0;
    static final int MODEL_COLUMN_NUM_FIELD_REVOCATION_DATE=1;
    static final int MODEL_COLUMN_NUM_FIELD_REASON_CODE=2;

    List<ERevocationInfo> revocationInfoList=new ArrayList<ERevocationInfo>();

    public void loadRevocationList(List<ERevocationInfo> revocationInfoList){
        this.revocationInfoList = revocationInfoList;
        fireTableDataChanged();
    }

    public ERevocationInfo getRevocationInfo(int row){
        return revocationInfoList.get(row);
    }
    @Override
    public int getRowCount() {
        if(revocationInfoList == null){
            return 0;
        }
        return revocationInfoList.size();
    }

    @Override
    public int getColumnCount() {
        return MODEL_COLUMN_COUNT;
    }

    @Override
    public String getColumnName(int column) {
        switch (column){
            case  MODEL_COLUMN_NUM_FIELD_SERIAL_NUMBER:
                return Bundle.getString("ERevokedCertsModel.serialnumber");
            case MODEL_COLUMN_NUM_FIELD_REVOCATION_DATE:
                return Bundle.getString("ERevokedCertsModel.revocationdate");
            case MODEL_COLUMN_NUM_FIELD_REASON_CODE:
                return Bundle.getString("ERevokedCertsModel.reasoncode");
            default:
                return "";
        }
    }

    @Override
    public Object getValueAt(int row, int column) {
        ERevocationInfo revocationInfo = revocationInfoList.get(row);
        switch (column){
            case  MODEL_COLUMN_NUM_FIELD_SERIAL_NUMBER:
                return revocationInfo.getSerialNumber();
            case MODEL_COLUMN_NUM_FIELD_REVOCATION_DATE:
                return new EDate(revocationInfo.getRevocationDate());
            case MODEL_COLUMN_NUM_FIELD_REASON_CODE:
                return revocationInfo.getReasonCodeStr();
            default:
                return "";
        }
    }

    @Override
    public boolean isCellEditable(int row, int column) {
        return false;
    }
}
